import { ElMessage } from "element-plus";
import { Bell } from "@element-plus/icons-vue";

function success(msg: string, duration?: number) {
  ElMessage({
    showClose: true,
    message: `${msg}`,
    type: "success",
    icon: Bell as any,
    duration: calculateDuration(duration),
  });
}

function calculateDuration(duration: number | undefined): number | undefined {
  if (duration === undefined) {
    return 5000;
  }
  if (duration) {
    return duration * 1000;
  } else {
    return duration;
  }
}

export const msgbox = {
  success,
};
